package com.hxzon.netty.statistics.dao;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.hxzon.netty.statistics.model.LoginDetail;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class StatisticsClientDao {

    private static final Logger logger = LoggerFactory.getLogger(StatisticsClientDao.class);
    @Resource
    private SqlMapClient sqlMapClient;

    @SuppressWarnings("unchecked")
    public List<LoginDetail> listLoginDetail() {
        try {
            return (List<LoginDetail>) sqlMapClient.queryForList("listLoginDetail");
        } catch (SQLException e) {
            logger.error(e.getMessage(), e);
            return Collections.emptyList();
        }
    }

    public void insertLoginDetail(LoginDetail loginDetail) {
        try {
            sqlMapClient.insert("insertLoginDetail", loginDetail);
        } catch (SQLException e) {
            logger.error(e.getMessage(), e);
            throw new RuntimeException(e);
        }
    }

}
